<?

class MceSelectFile extends Button {

    function MceSelectFile() {
        Event::registerEventHandler('RENDER_SELECTED_FILE',array('MceSelectFile','onSelectedFileRender'));
    }

    function render($sel) {
        if ($sel->isFileSelected()) {
            return $this->renderDefaultButton('mceselectfile',Config::getLink($_GET['path'],$_GET['object'],'action=mceselectfile'),'Select file','Select file');
        } else {
            return $this->renderDisabledButton('mceselectfile','Select File','Select File');
        }
    }

    function action($sel) {
        $x = $sel->getCurrentDirNameRel();
        $y = (isset($_GET['object']) ? $_GET['object'] : '');
        echo "<script language='javascript'>window.opener.document.win.document.getElementById(window.opener.document.fn).value = 'http://{$_SERVER['SERVER_NAME']}".substr($sel->_root,1)."/{$x}{$y}'; self.close();</script>";
        exit;
    }

    function onSelectedFileRender($res) {
        $res = str_replace('&object=','&action=mceselectfile&object=',$res);
        return $res;
    }

}

?>